package com.alumni_circle.controller.me;

import com.alumni_circle.core.config.SysLog;
import com.alumni_circle.core.entity.BaseId;
import com.alumni_circle.core.entity.PageBase;
import com.alumni_circle.core.entity.ResponseListModel;
import com.alumni_circle.core.entity.ResponseModel;
import com.alumni_circle.core.utils.ModelUtils;
import com.alumni_circle.core.web.BaseController;
import com.alumni_circle.entity.me.User;
import com.alumni_circle.entity.me.UserApply;
import com.alumni_circle.entity.me.VO.UserApplySearchVO;
import com.alumni_circle.entity.me.VO.UserApplyUpdateVO;
import com.alumni_circle.entity.me.VO.UserApplyViewVO;
import com.alumni_circle.service.me.impl.UserApplyServiceImpl;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 龙小虬
 * @since 2020-07-06 22:58
 */
@Api(tags = "审核审核管理")
@Controller
@RequestMapping("/userApply")
public class UserApplyController extends BaseController<User> {

    @Resource
    private UserApplyServiceImpl userApplyService;


    /**
     * 增加、更新审核信息
     *
     * @param userApply
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/addUserApply", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "新增审核信息", notes = "增加审核信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="增",accessInfo="新增审核信息",url="/userApply/addUserApply")
    public ResponseModel addUser(@ApiParam(required = true, name = "user")
                                 @RequestBody UserApply userApply) {
        userApplyService.save(userApply);
        return null;
    }

    @ResponseBody
    @RequestMapping(value = "/updateUserApply", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "更新审核信息", notes = "更新审核信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="改",accessInfo="更新审核信息",url="/userApply/updateUserApply")
    public ResponseModel updateUser(@ApiParam(required = true, name = "baseId")
                                        @RequestBody UserApplyUpdateVO userApplyUpdateVO) {
        userApplyService.updateById(ModelUtils.transform(userApplyUpdateVO,UserApply.class));
        return null;
    }


    @ResponseBody
    @RequestMapping(value = "/selectUserApply", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "查询审核信息", notes = "查询审核信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="查",accessInfo="查询审核信息",url="/userApply/selectUserApply")
    public ResponseModel selectUserCode(@ApiParam(required = true, name = "baseId")
                                        @RequestBody UserApplySearchVO userApplySearchVO) {
        List<UserApply> list = userApplyService.search(userApplySearchVO.getEmail(),userApplySearchVO.getRole(),userApplySearchVO.getPass(),userApplySearchVO.getId(),userApplySearchVO.getName(),userApplySearchVO.getPhone());
        return new ResponseModel<>(list);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteUserApply", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "删除审核信息", notes = "删除审核信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="删",accessInfo="删除审核信息",url="/userApply/deleteUserApply")
    public ResponseModel deleteUser(@ApiParam(required = true, name = "baseId")
                                    @RequestBody BaseId baseId) {

        return null;
    }


    @ResponseBody
    @RequestMapping(value = "/getAllUserApply", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "查询符合条件审核信息", notes = "查询符合条件审核信息", httpMethod = "POST", response = ResponseModel.class)
    @SysLog(type="查",accessInfo="查询符合条件审核信息",url="/userApply/getAllUserApply")
    public ResponseListModel getAllUser(@ApiParam(required = true, name = "pageBase")
                                        @RequestBody PageBase pageBase) {
        PageHelper.startPage(pageBase.getPageNum(),pageBase.getPageSize());
        return new ResponseListModel<>(ModelUtils.copyListProperties(userApplyService.list(), UserApplyViewVO.class));
    }

}